﻿namespace Core
{
    public abstract class EventHandler<T> : Core.Component, IAwake
        where T : Entity
    {
        public T Unit { get; private set; }

        // ReSharper disable once InconsistentNaming
        protected EventComponent messenger;

        public virtual void Awake()
        {
            Unit = Entity as T;
            messenger = Unit.Get<EventComponent>();
            AddEventListener();
        }

        public override void Dispose()
        {
            if (IsDisposed) return;

            RemoveEventListener();

            base.Dispose();
        }

        protected abstract void AddEventListener();
        protected abstract void RemoveEventListener();
    }
}
